﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Utility;
using LotteryVote.Entity;
using LotteryVote.Logic.Exceptions;
using LotteryVote.Logic.Web;

namespace LotteryVote
{
    public partial class UpdateBetGameLimit : CompanyPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            Execute(() =>
            {
                if (lv_gameplayway.GamePlayWayId == 0)
                    throw new PromptException("请选择一个游戏玩法!");
                BetLimitFacade limitFacade = new BetLimitFacade();
                List<GameBetLimit> limitList = new List<GameBetLimit>();
                foreach (var companyType in EnumHelper.ToList<CompanyType>())
                {
                    decimal limitValue;
                    string limitStr = Request.Form[companyType.ToString()];
                    if (string.IsNullOrEmpty(limitStr) || !decimal.TryParse(limitStr, out limitValue))
                        continue;
                    var limit = new GameBetLimit
                    {
                        GamePlayWayId = lv_gameplayway.GamePlayWayId,
                        LimitValue = limitValue,
                        CompanyType = companyType
                    };
                    limitList.Add(limit);
                }
                limitFacade.UpdateAllUserGameBetLimit(lv_gameplayway.GamePlayWayId, limitList);
                ShowMessage("Success", GetGlobalResourceObject("Resource", "Success").ToString());
            });
        }
    }
}